//
//  AppDelegate.swift
//  555wobo
//
//  Created by 黄某某 on 15/12/15.
//  Copyright © 2015年 黄某某. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.
        UINavigationBar.appearance().tintColor = UIColor.orangeColor()
        window = UIWindow(frame:UIScreen.mainScreen().bounds)
        
        window?.rootViewController = defaultViewController()
        
//        window?.rootViewController = HZWelcomeViewController()
//        window?.rootViewController = HZNewFeatureViewController()
        
        window?.makeKeyAndVisible()
        
        
        return true
    }
    func switchRootViewController(isMain: Bool) {
        window?.rootViewController = isMain ? HZTabBarController() : HZWelcomeViewController()
    }
    private func defaultViewController() -> UIViewController{
        if !HZUserAccount.userLogin{
            return HZTabBarController()
        }
        return isNewVersion() ? HZNewFeatureViewController() : HZWelcomeViewController()
    }
    private func isNewVersion() ->Bool{
        let currentVersion = NSBundle.mainBundle().infoDictionary!["CFBundleShortVersionString"] as! String
        print("当前版本: \(currentVersion)")
        
        let sandboxVersionKey = "sandboxVersionKey" // 保存到沙盒的key
        let sandboxVersion = NSUserDefaults.standardUserDefaults().stringForKey(sandboxVersionKey)
        print("沙盒版本: \(sandboxVersion)")
        
        NSUserDefaults.standardUserDefaults().setObject(currentVersion, forKey: sandboxVersionKey)
        NSUserDefaults.standardUserDefaults().synchronize()
        
        return currentVersion != sandboxVersion
    }




}

